package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.feign.search.SearchFeignClient;
import com.atguigu.gmall.product.search.vo.SearchParamVo;
import com.atguigu.gmall.product.search.vo.SearchRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class SearchController {
    @Autowired
    SearchFeignClient searchFeignClient;

    @GetMapping("/list.html")
    public String search(SearchParamVo searchParamVo, Model model){
        SearchRespVo searchRespVo = searchFeignClient.search(searchParamVo).getData();

        // 1 searchParam{keyword,trademark，props，trademark,order}
        model.addAttribute("searchParam",searchParamVo);

        // 2 trademarkParam-->品牌面包屑 --> 字符串
        model.addAttribute("trademarkParam",searchRespVo.getTrademarkParam() );

        // 3 List<propsParamList>-->{attrName,attrValue}-->平台属性面包屑
        model.addAttribute("propsParamList",searchRespVo.getPropsParamList());

        // 4 List<trademarkList>-->{tmName,tmId,tmName,tmLogoUrl,tmName}-->品牌列表
        model.addAttribute("trademarkList",searchRespVo.getTrademarkList());

        // 5 List<attrsList>-->{attrName,attrValueList,attrId,attrName,}-->属性列表
        model.addAttribute("attrsList",searchRespVo.getAttrsList());

        // 6 String-->urlParam -->URL参数
        model.addAttribute("urlParam",searchRespVo.getUrlParam());

        //7 Map<K，V>-->orderMap{type,sort} -->排序信息
        model.addAttribute("orderMap",searchRespVo.getOrderMap());

        //8 List<goodsList>-->{id,defaultImg,price,title,} -->商品列表
        model.addAttribute("goodsList",searchRespVo.getGoodsList());

        //9 pageNo-->分页信息
        model.addAttribute("pageNo",searchRespVo.getPageNo());

        //10 totalPages--> 总页码
        model.addAttribute("totalPages",searchRespVo.getTotalPages());
        return "list/index";
    }
}
